home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 34 / Amiga Format CD34 (1998-11-20)(Future Publishing)(GB)[!][Christmas issue].iso / -seriously_amiga- / programming / c / mesa-2.6 / src-glut / glutattachdetachmenu.c < prev    next >
C/C++ Source or Header  |  1998-10-01  |  4KB  |  213 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  2.0
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21.  
  22. /*
  23.  * glutAttachDetachMenu.c
  24.  *
  25.  * Version 1.0  27 Jun 1998
  26.  * by Jarno van der Linden
  27.  * jarno@kcbbs.gen.nz
  28.  *
  29.  * Version 2.0  16 Aug 1998
  30.  * by Jarno van der Linden
  31.  * jarno@kcbbs.gen.nz
  32.  *
  33.  * - Changed to runtime library format
  34.  *
  35.  */
  36.  
  37.  
  38. #include <proto/gadtools.h>
  39. #include <proto/intuition.h>
  40.  
  41. #include <stdlib.h>
  42.  
  43. #include "glutstuff.h"
  44.  
  45.  
  46. struct Menu *GetMenuPointer(int button)
  47. {
  48.     struct Menu *menu;
  49.  
  50.     menu = glutstuff.curwin->menu;
  51.  
  52.     switch(button)
  53.     {
  54.         case GLUT_RIGHT_BUTTON:
  55.             menu = menu->NextMenu;
  56.         case GLUT_MIDDLE_BUTTON:
  57.             menu = menu->NextMenu;
  58.         case GLUT_LEFT_BUTTON:
  59.             break;
  60.     }
  61.  
  62.     return(menu);
  63. }
  64.  
  65.  
  66. int CountMenuEntries(struct GlutMenu *gm)
  67. {
  68.     struct GlutMenuEntry *gme;
  69.     int n;
  70.  
  71.     n = 1;    /* This menu item */
  72.  
  73.     gme = gm->entries;
  74.  
  75.     while(gme)
  76.     {
  77.         if(gme->issubmenu)
  78.             n += CountMenuEntries(stuffGetMenu(gme->value))+2;    /* Will include (sub)menu item */
  79.         else
  80.             n++;    /* Just this menu entry */
  81.  
  82.         gme = gme->next;
  83.     }
  84.  
  85.     return(n);
  86. }
  87.  
  88.  
  89. void FillEntry(struct NewMenu **nm,UBYTE nm_type, STRPTR nm_Label, APTR nm_UserData)
  90. {
  91.     (*nm)->nm_Type = nm_type;
  92.     (*nm)->nm_Label = nm_Label;
  93.     (*nm)->nm_CommKey = 0;
  94.     (*nm)->nm_Flags = 0;
  95.     (*nm)->nm_MutualExclude = 0;
  96.     (*nm)->nm_UserData = nm_UserData;
  97.     (*nm)++;
  98. }
  99.  
  100.  
  101. void FillMenu(struct GlutMenu *gm, struct NewMenu **nm,UBYTE type)
  102. {
  103.     struct GlutMenuEntry *gme;
  104.  
  105.     gme = gm->entries;
  106.     while(gme)
  107.     {
  108.         FillEntry(nm, type, gme->name, gme);
  109.         if(gme->issubmenu)
  110.         {
  111.             if(type == NM_SUB)
  112.             {
  113.                 ((*nm)-1)->nm_Flags = NM_ITEMDISABLED;
  114.                 FillEntry(nm, type, NM_BARLABEL, 0);
  115.             }
  116.             FillMenu(stuffGetMenu(gme->value),nm,NM_SUB);
  117.             if(type == NM_SUB)
  118.                 FillEntry(nm, type, NM_BARLABEL, 0);
  119.         }
  120.         gme = gme->next;
  121.     }
  122. }
  123.  
  124.  
  125. struct MenuItem *MakeMenu(struct GlutMenu *gm)
  126. {
  127.     struct NewMenu *nm,*nmp;
  128.     int n;
  129.     struct MenuItem *menu;
  130.  
  131.     n = CountMenuEntries(gm);
  132.     menu = NULL;
  133.  
  134.     nm = calloc(n+1, sizeof(struct NewMenu));
  135.     if(nm)
  136.     {
  137.         nmp = nm;
  138.  
  139.         FillMenu(gm,&nmp,NM_ITEM);
  140.         FillEntry(&nmp, NM_END, NULL, 0);
  141.  
  142.         menu = (struct MenuItem *)CreateMenus(nm, TAG_END);
  143.  
  144.         free(nm);
  145.     }
  146.  
  147.     return(menu);
  148. }
  149.  
  150.  
  151. void RedoMenu(int button, struct GlutMenu *glutmenu)
  152. {
  153.     struct Menu *menu;
  154.     struct MenuItem *menuitems;
  155.  
  156.     menu = GetMenuPointer(button);
  157.     ClearMenuStrip(glutstuff.curwin->window);
  158.     FreeMenus(menu->FirstItem);
  159.     if(glutmenu)
  160.     {
  161.         menuitems = MakeMenu(glutmenu);
  162.         menu->FirstItem = menuitems;
  163.         LayoutMenuItems(menuitems,glutstuff.curwin->vi,
  164.                 GTMN_Menu,        menu,
  165.                 TAG_END);
  166.     }
  167.     else
  168.     {
  169.         menu->FirstItem = NULL;
  170.     }
  171.     SetMenuStrip(glutstuff.curwin->window,glutstuff.curwin->menu);
  172. }
  173.  
  174.  
  175. __asm __saveds void glutAttachMenu( register __d0 int button )
  176. {
  177.     switch(button)
  178.     {
  179.         case GLUT_LEFT_BUTTON:
  180.             glutstuff.curwin->leftmenu = glutstuff.curmenu;
  181.             glutstuff.curwin->needleftmenu = TRUE;
  182.             break;
  183.         case GLUT_MIDDLE_BUTTON:
  184.             glutstuff.curwin->middlemenu = glutstuff.curmenu;
  185.             glutstuff.curwin->needmiddlemenu = TRUE;
  186.             break;
  187.         case GLUT_RIGHT_BUTTON:
  188.             glutstuff.curwin->rightmenu = glutstuff.curmenu;
  189.             glutstuff.curwin->needrightmenu = TRUE;
  190.             break;
  191.     }
  192. }
  193.  
  194.  
  195. __asm __saveds void glutDetachMenu( register __d0 int button )
  196. {
  197.     switch(button)
  198.     {
  199.         case GLUT_LEFT_BUTTON:
  200.             glutstuff.curwin->leftmenu = NULL;
  201.             glutstuff.curwin->needleftmenu = TRUE;
  202.             break;
  203.         case GLUT_MIDDLE_BUTTON:
  204.             glutstuff.curwin->middlemenu = NULL;
  205.             glutstuff.curwin->needmiddlemenu = TRUE;
  206.             break;
  207.         case GLUT_RIGHT_BUTTON:
  208.             glutstuff.curwin->rightmenu = NULL;
  209.             glutstuff.curwin->needrightmenu = TRUE;
  210.             break;
  211.     }
  212. }
  213.